package com.rao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rao.entity.Score;
import com.rao.entity.Student;
import com.rao.entity.VO.ScoreVO;
import com.rao.mapper.ScoreMapper;
import com.rao.mapper.StudentMapper;
import com.rao.service.IScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 分数表 服务实现类
 * </p>
 *
 * @author rao3030
 * @since 2021-11-04
 */
@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements IScoreService {

    @Resource
    private StudentMapper studentMapper;
    @Resource
    private ScoreMapper scoreMapper;

    public List<ScoreVO> getByStuTime(String studentName, Date startExamDate, Date endExamDate) {
        QueryWrapper<Student> studentQueryWrapper = new QueryWrapper<>();
        studentQueryWrapper.lambda().eq(Student::getName, studentName);
        Student student = studentMapper.selectOne(studentQueryWrapper);
        Integer studentId = student.getId();
        List<ScoreVO> scoreVOS = scoreMapper.listByStuNameAndTime(studentId, startExamDate,endExamDate);
        scoreVOS.forEach(s -> s.setStudentName(studentName));
        return scoreVOS;
    }
}
